﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Threading;

namespace spawn
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {


        public MainWindow()
        {
            InitializeComponent();
        }

        public void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                Process p;
                App app = ((App)Application.Current);
                if (app.args.Length >= 1)
                {
                    int number = Int32.Parse(app.args[0]);
                    if (number > 0)
                    {
                        number--;
                        ProcessStartInfo info = new ProcessStartInfo();
                        info.FileName = "spawn.exe";
                        info.Arguments = number.ToString();
                        p = Process.Start(info);
                    }
                }
            }
            finally
            {

                System.Threading.Timer t = new Timer(new TimerCallback(delegate(object obj)
                {
                    Dispatcher.BeginInvoke((Action)delegate()
                    {
                        Close();
                    });
                }), null, 8000, 60000);
            }
        }

        int i = 0;
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            button1.Content = i++;
        }
    }
}
